<template>
  <div>
      <el-form :model="dynamicValidateForm" ref="dynamicValidateForm" label-width="100px" class="demo-dynamic">
  
  <el-form-item

    v-for="(domain, index) in dynamicValidateForm.domains"
    :label="'ISBN-' + index"
    :key="domain.key"
    :prop="'domains.' + index + '.value'"
    :rules="{
      required: true, message: 'ISBN不能为空', trigger: 'blur'
    }"
  >
    <el-input style=' width: 40%;' v-model="domain.value"></el-input><el-button  type="danger" style=" margin-left: 20px;" @click.prevent="removeDomain(domain)">删除</el-button>
  </el-form-item>
  <el-form-item>
   
    <el-button @click="addDomain">新增ISBN</el-button>
    <el-button @click="resetForm('dynamicValidateForm')">重置</el-button>
     <el-button type="primary" @click="submitForm('dynamicValidateForm')">下一步,确定图书详情</el-button>
  </el-form-item>
</el-form>
  </div>
</template>

<script>
 export default {
    data() {
      return {
        dynamicValidateForm: {
          domains: [{
            value: ''
          }],
         
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
              this.$emit('nextStep',this.dynamicValidateForm.domains)
           

          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
      removeDomain(item) {
        var index = this.dynamicValidateForm.domains.indexOf(item)
        if (index !== -1) {
          this.dynamicValidateForm.domains.splice(index, 1)
        }
      },
      addDomain() {
          console.log(this.dynamicValidateForm.domains);
        this.dynamicValidateForm.domains.push({
          value: '',
          key: Date.now()
        });
      },

    }
  }
</script>

<style>

</style>